class VoicePlayer {
  lastTask = null
  audio = document.createElement('AUDIO')
  play(url, success, ended) {
    if (this.lastTask) {
      this.destroyLastTask()
    }
    this.lastTask = {
      success: success,
      ended: ended
    }
    this.audio.src = url
    this.audio.autoplay = false
    this.audio.addEventListener('play', this.lastTask.success, false)
    this.audio.addEventListener('ended', this.lastTask.ended, false)
    this.audio.play()
  }
  destroyLastTask() {
    this.audio.pause()
    this.audio.removeEventListener('play', this.lastTask.success, false)
    this.audio.removeEventListener('ended', this.lastTask.ended, false)
  }
}
module.exports = new VoicePlayer()